package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtCommissionDetail;
import com.ruoyi.business.service.IJtCommissionDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 佣金明细Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/commission")
public class JtCommissionDetailController extends BaseController
{
    private String prefix = "business/commission";

    @Autowired
    private IJtCommissionDetailService jtCommissionDetailService;

    @RequiresPermissions("business:commission:view")
    @GetMapping()
    public String commission()
    {
        return prefix + "/commission";
    }

    /**
     * 查询佣金明细列表
     */
    @RequiresPermissions("business:commission:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtCommissionDetail jtCommissionDetail)
    {
        startPage();
        List<JtCommissionDetail> list = jtCommissionDetailService.selectJtCommissionDetailList(jtCommissionDetail);
        return getDataTable(list);
    }

    /**
     * 导出佣金明细列表
     */
    @RequiresPermissions("business:commission:export")
    @Log(title = "佣金明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtCommissionDetail jtCommissionDetail)
    {
        List<JtCommissionDetail> list = jtCommissionDetailService.selectJtCommissionDetailList(jtCommissionDetail);
        ExcelUtil<JtCommissionDetail> util = new ExcelUtil<JtCommissionDetail>(JtCommissionDetail.class);
        return util.exportExcel(list, "佣金明细数据");
    }

    /**
     * 新增佣金明细
     */
    @RequiresPermissions("business:commission:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存佣金明细
     */
    @RequiresPermissions("business:commission:add")
    @Log(title = "佣金明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtCommissionDetail jtCommissionDetail)
    {
        return toAjax(jtCommissionDetailService.insertJtCommissionDetail(jtCommissionDetail));
    }

    /**
     * 修改佣金明细
     */
    @RequiresPermissions("business:commission:edit")
    @GetMapping("/edit/{detailId}")
    public String edit(@PathVariable("detailId") Long detailId, ModelMap mmap)
    {
        JtCommissionDetail jtCommissionDetail = jtCommissionDetailService.selectJtCommissionDetailByDetailId(detailId);
        mmap.put("jtCommissionDetail", jtCommissionDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存佣金明细
     */
    @RequiresPermissions("business:commission:edit")
    @Log(title = "佣金明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtCommissionDetail jtCommissionDetail)
    {
        return toAjax(jtCommissionDetailService.updateJtCommissionDetail(jtCommissionDetail));
    }

    /**
     * 删除佣金明细
     */
    @RequiresPermissions("business:commission:remove")
    @Log(title = "佣金明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtCommissionDetailService.deleteJtCommissionDetailByDetailIds(ids));
    }
}
